<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@page pageEncoding="UTF-8" %>
<%@page contentType="text/html; charset=UTF-8" language="java"%>
<%@ taglib uri="http://struts.apache.org/tags-html"  prefix="html"%>
<%@ taglib uri="http://struts.apache.org/tags-bean"  prefix="bean"%>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic"%>
<%@ taglib uri="http://displaytag.sf.net" prefix="display" %>
<%@page import="com.kcs.common.utils.commonUtils"%>
<%@page import="com.kcs.common.utils.PropsUtils"%>
<%@page import="com.kcs.common.utils.Constant"%>

<html>
<head>
<title>FX Margin - Import Deposit/Withdraw to FX Margin</title>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
<script type="text/javascript" src="jsp/script/jquery/plugin/fancybox/jquery.easing-1.3.pack.js"></script>
<script type="text/javascript" src="jsp/script/jquery/plugin/fancybox/jquery.fancybox-1.3.4.js"></script>
<script type="text/javascript" src="jsp/script/jquery/plugin/fancybox/jquery.fancybox-1.3.4.pack.js"></script>   
<script type="text/javascript" src="jsp/script/jsDatePick.full.1.3.js"></script>   	 	 	
<script type="text/javascript" src="jsp/script/common.js"></script>  
<link rel="stylesheet" type="text/css" href="jsp/script/jquery/plugin/fancybox/jquery.fancybox-1.3.4.css"/>
<link rel="stylesheet" type="text/css" href="jsp/css/table.css"/>
<link rel="stylesheet" type="text/css" href="jsp/css/fxmarginStyle.css"/>
<link rel="stylesheet" type="text/css" href="jsp/css/jsDatePick_ltr.css" />


<script type="text/javascript">
	window.onload = function(){
		new JsDatePick({
			useMode:2,
			target:"inStartDate",
			dateFormat:"%d/%m/%Y"});

		new JsDatePick({
			useMode:2,
			target:"inEndDate",
			dateFormat:"%d/%m/%Y"});

		highlightData();
	};

	function validateSearchImportDW(){
		var inCifNo = document.getElementsByName("inCifNo")[0];
		var inACName = document.getElementsByName("inACName")[0];
		var inStartDate = document.getElementsByName("inStartDate")[0];
		var inEndDate = document.getElementsByName("inEndDate")[0];

		if(inCifNo.value=="" && inACName.value=="" && inStartDate.value=="" && inEndDate.value==""){
			alert(m_please_1_condition);
			return false;
		}

		return true;
	}

	function searchImportDW(){
		var tranCode = document.getElementsByName("tranCode")[0];

		if(validateSearchImportDW()){
			tranCode.value = "searchImportDW";
			document.forms[0].submit();
		}
		
	}

	function resetForm(){
		var tranCode = document.getElementsByName("tranCode")[0];
		tranCode.value = "resetForm";

		document.forms[0].submit();
	}

	function printImportDW(){
		var tranCode = document.getElementsByName("tranCode")[0];
		tranCode.value = "printImportDW";

		document.forms[0].submit();
	}

	// for popup customer //
	function onPopup(id, src, width, height){
		g_datacustomer = null;
		jQuery("#" + id + "_iframe").html("");
		src = "http://" + window.location.host + "/FxMargin/" + src + ".do?pAction=init";
		var html = "<center><iframe src='" + src +"' height='" + height +"px' width='" + width + "px' id='myIframe'></iframe></center>";

		jQuery("#" + id + "_iframe").html(html);

		openPopup(id);
		
	}

	function select(data){
		g_datacustomer = data;
	}
	
	function onCustomer(){
		/*	global variable 'g_datacustomer' is use	*/
 		
 		if(g_datacustomer != null){
 			jQuery("#inCifNo").val(g_datacustomer.cifNo);
 			jQuery("#inACName").val(g_datacustomer.marginAccName);	
 			jQuery.fancybox.close();
 	 	}
		
	}
	
	function offCustomer(){
		jQuery.fancybox.close();
	}
	// for popup customer //
	
	function highlightData(){
		var v_table = document.getElementById("data");
		var typeColumn = 5;
		var amountColumn = 6;
		var refNoColumn = 7;
		var type1 = "";
		var type2 = "";
		var amount1 = "";
		var amount2 = "";
		var refNo1 = "";
		var refNo2 = "";
		
		if(v_table){
			for(var i=1; i<v_table.rows.length; i++){
				if(i%2==0){
					type1 = v_table.rows[i-1].cells[typeColumn];
					type2 = v_table.rows[i].cells[typeColumn];
					amount1 = v_table.rows[i-1].cells[amountColumn];
					amount2 = v_table.rows[i].cells[amountColumn];
					refNo1 = v_table.rows[i-1].cells[refNoColumn];
					refNo2 = v_table.rows[i].cells[refNoColumn];

					if(refNo1.innerHTML == refNo2.innerHTML){
						if(type1.innerHTML != type2.innerHTML){
							type1.style.color = "red";
							type2.style.color = "red";
						}
						if(amount1.innerHTML != amount2.innerHTML){
							amount1.style.color = "red";
							amount2.style.color = "red";
						}
					}
				}		
			}
		}

	}

</script>

</head>
<body>
	<!-- HEADER MENU -->
	<%@ include	file="include/headerMenu.jsp"%> 

	<center>
		<div id="divImportDepositWithdraw" style="width:95%;">
			<html:form action="/ImportDepositWithdrawAction.do" style="margin:0px;">
				<input type="hidden" name="tranCode" value=""/>
				
				<table class="MarginHeader" width="100%" style="text-align: left;">
					<tr>
						<td>
							Import Deposit/Withdraw to FX Margin
						</td>
					</tr>
				</table>
				<table width="100%" border="0" cellspacing="0" cellpadding="0">
					<tr>
						<td>
							<center>
								<table class="MarginCriteria" width="100%">
									<tr>
										<td width="30%" align="right" valign="bottom">CIF No.</td>
										<td width="12%" align="left" valign="bottom">
											<html:text styleId="inCifNo" property="inCifNo"/>
										</td>
										<td width="10%" align="right" valign="bottom">A/C Name</td>
										<td width="48%" align="left" valign="bottom">
											<html:text styleId="inACName" property="inACName" size="50"/>
											&nbsp;&nbsp;
											<img src="jsp/images/btn/glass_search.gif" style="width:30px;cursor:pointer;" onclick="onPopup('popupCustomer','PopupCustomerAction',700,540);" />
										</td>
									</tr>
									<tr>
										<td align="right">Start Date</td>
										<td align="left"><html:text styleId="inStartDate" property="inStartDate" maxlength="10"/></td>
										<td align="right">End Date</td>
										<td align="left"><html:text styleId="inEndDate" property="inEndDate" maxlength="10"/></td>
									</tr>
									<tr>
										<td align="right">Search Type</td>
										<td align="left" colspan="3">
											<html:radio property="searchType" value="<%=Constant.SEARCH_TYPE_ALL%>" ></html:radio>
											All
											&nbsp;
											<html:radio property="searchType" value="<%=Constant.SEARCH_TYPE_DIFF%>" ></html:radio>
											Diff
										</td>
									</tr>
									<tr>
										<td colspan="4">
											<center>
												<input type="button" class="button" value="Search" onclick="searchImportDW();"/>
												&nbsp;
												&nbsp;
												<input type="button" class="button" value="Reset" onclick="resetForm();"/>
											</center>
										</td>
									</tr>
								</table>
							</center>
						</td>
					</tr>
					<tr>
						<td>
							<br><br><br>
							<center>
								<%
									Object err = request.getAttribute(Constant.ERR_ATTR);
								
									if(err != null){
										%>
											<script type="text/javascript">
												alert("<%=err%>");
											</script>
										<%
										
									}else{
										%>
											<logic:present name="<%=Constant.SHOW_RESULT%>">
												<div class="MarginTable" >
													<display:table id="data" name="sessionScope.ImportDepositWithdrawActionForm.importDWList" requestURI="/ImportDepositWithdrawAction.do" pagesize="10" >
														<display:column property="rowNum" title="No" sortable="false" style="text-align:center;"/>
														<display:column property="date" title="Date"   sortable="false" style="text-align:center;"/>
														<display:column property="cifNo" title="CIF No." sortable="false"/>			
														<display:column property="acNo" title="A/C No." sortable="false"/>
														<display:column property="acName" title="A/C Name" sortable="false"/>
														<display:column property="typeName" title="Type" sortable="false"/>
														<display:column property="amount" title="Amount (THB)" sortable="false" style="text-align:right;"/>
														<display:column property="refNo" title="Ref. No." sortable="false"/>
														<display:column property="entryBy" title="Entry By" sortable="false"/>
													</display:table>
												</div>
												
												<logic:notEmpty name="ImportDepositWithdrawActionForm" property="importDWList">
													<logic:equal name="ImportDepositWithdrawActionForm" property="searchType" value="<%=Constant.SEARCH_TYPE_DIFF%>">
														<br><br><br>
														<input type="button" class="button" value="Export Excel" onclick="printImportDW();"/>
													</logic:equal>
												</logic:notEmpty>
												
											</logic:present>
										<%
									}
								%>
		
							</center>
						</td>
					</tr>
				</table>	
				
				<div style="display:none">
			        <div id="popupCustomer" style="width:710px;height: 600px">
			        	<div id="popupCustomer_iframe"></div>
						<table width="100%">
							<tr>
								<td width="33%" align="center">
									<input type="button" value="Ok" class="button" onclick="onCustomer();"/>
								</td>
								<td width="34%" align="center">
									<input type="button" value="Close" class="button" onclick="offCustomer();"/>
								</td>
							</tr>
						</table>
			        </div>
			    </div>
			    
				<%@ include	file="include/footer.jsp"%> 
				<%@ include	file="include/message.jsp"%> 
			</html:form>
		</div>
	</center>
</body>
</html>